﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

[Serializable]
public class SerialBoneWeight
{
    public BWPair[] pairs = new BWPair[4];
    public static implicit operator SerialBoneWeight(BoneWeight bw)
    {
        var sbw = new SerialBoneWeight(bw);
        return sbw;
    }
    public SerialBoneWeight(BoneWeight bw)
    {
        pairs[0] = new BWPair(bw.boneIndex0, bw.weight0);
        pairs[1] = new BWPair(bw.boneIndex1, bw.weight1);
        pairs[2] = new BWPair(bw.boneIndex2, bw.weight2);
        pairs[3] = new BWPair(bw.boneIndex3, bw.weight3);
    }
}
[Serializable]
public class BWPair
{
    public int bone;
    public float weight;
    public BWPair() { }
    public BWPair(int bone, float weight)
    {
        this.bone = bone;
        this.weight = weight;
    }
}

[RequireComponent(typeof(VerticesSeletor))]
public class ViewVertexWeight : MonoBehaviour
{
    VerticesSeletor vs;
    SkinnedMeshRenderer smr;
    public SerialBoneWeight bw;
    void Start()
    {
        smr = GetComponent<SkinnedMeshRenderer>();
        vs = GetComponent<VerticesSeletor>();
        vs.selectChange += ViewBoneWeights;
    }
    void ViewBoneWeights(int b)
    {
        var boneWeights = smr.sharedMesh.boneWeights;
        bw = boneWeights[b];
    }
}
